from pms.common.views import PostFormula
from user.models import Role
from user.utils.permission import get_pids_by_rid


class API(PostFormula):
    def handle(self, req):
        roles = Role.objects.all()
        return self.success_respond({
            'list': [{
                'id': role.id,
                'name': role.name,
                'permissions': list(get_pids_by_rid(role.id))
            } for role in roles]
        })
